<?php
/**
 * 主页控制器
 */

class IndexAction extends BaseAction {
    public function __construct() {
        parent::__construct();

        $this->subnavs = array(
            array(
                'name' => '主页',
                'url' => U('Index/index'),
                'action' => 'index',
                'icon' => 'home',
            ),
            array(
                'name' => '历届成员',
                'url' => U('Index/sessions'),
                'action' => '
                    member, sessions, departments, members',
                'icon' => 'group',
            ),
        );
    }

    /** 成员信息页 */
    public function member() {
        $this->member = D('Member')
            ->where(array('id' => $this->_param('id')))
            ->relation(true)
            ->find();
        $this->breadcrumbsPush('历届成员', U('Index/sessions'));
        $this->breadcrumbsPush(
            $this->member['session']['name'],
            U('Index/departments', array(
                'session' => $this->member['session']['id'])));
        $this->breadcrumbsDepartment($this->member['department']);
        $this->breadcrumbsPush($this->member['name'], '');
        $this->display();
    }

    /** 历届 */
    public function sessions() {
        $this->breadcrumbsPush('历届成员', '');
        $this->sessions = D('Session')->select();
        $this->display();
    }

    public function departments() {
        $session = D('Session')
            ->where(array('id' => $this->_param('session')))
            ->relation(true)
            ->find();
        $this->departments = $session['departments'];
        $this->breadcrumbsPush('历届成员', U('Index/sessions'));
        $this->breadcrumbsPush($session['name'], '');
        $this->display();
    }

    public function members() {
        $department = D('Department')
            ->where(array('id' => $this->_param('department')))
            ->relation(true)
            ->find();
        $this->breadcrumbsPush('历届成员', U('Index/sessions'));
        $this->breadcrumbsSession($department['session']);
        $this->breadcrumbsPush($department['name']);
        $this->members = $department['members'];
        $this->display();
    }

    /** 面包屑导航 - 届 */
    protected function breadcrumbsSession($session) {
        $this->breadcrumbsPush(
            $session['name'],
            U('Index/departments', array(
                'session' => $session['id'])));
    }
    /** 面包屑导航 - 部门 */
    protected function breadcrumbsDepartment($department) {
        $this->breadcrumbsPush(
            $department['name'],
            U('Index/members', array('department' => $department['id'])));
    }
}
